package com.weishe.hive;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class CreateTable {

	public static void main(String[] args) {
		Connection conn =null;
		try {
			Class.forName("org.apache.hive.jdbc.HiveDriver");
			conn = DriverManager.getConnection(
					"jdbc:hive2://node5:10000/default", "root", "");
			// ResultSet set = st.executeQuery("select count(*) from weibo");
			// while(set.next()){
			// System.out.println(set.getInt(1));
			// }

			// boolean f=
			// st.execute("create table t_class( id int,name string ) row format delimited fields terminated by ','");
			// System.out.println(f);
			// st.execute("add jar /root/to_date.jar");
			// String sql
			// ="create temporary function my_to_date as 'com.bjsxt.hive.StringToDate' ";
			String sql = "create table trackinfo ( id string,url string,referer string,session_id string,ip string) partitioned by (ds string) ROW FORMAT DELIMITED   FIELDS TERMINATED BY ','STORED AS TEXTFILE";
			PreparedStatement ps = conn.prepareStatement(sql);

			ps.execute();

//			sql = "select my_to_date(name,'yyyyMMdd HHmmss') from t_class where id=?";

//			ps = conn.prepareStatement(sql);
//			ps.setInt(1, 1);

//			ResultSet set = ps.executeQuery();
//			while (set.next()) {
//				Object o = set.getObject(1);
//				System.out.println(o.getClass().getName());
//				System.out.println(o);
//			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(conn!=null)
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
